
var swiper = new Swiper('.swiper-container', {
    pagination: '.swiper-container>.swiper-pagination',
    slidesPerView: 'auto',
    direction: 'vertical',
    mousewheelControl: false,
    freeMode: true,
});
var swiper = new Swiper('.lunbo', {
    pagination: '.lunbo>.swiper-pagination',
    paginationClickable: true,
    spaceBetween: 30,
    centeredSlides: true,
    mousewheelControl: false,
    autoplay: 5000,
    autoplayDisableOnInteraction: false,
    effect: 'fade',
});

$(function(){    
    var slideMenu=function(o){
        var winWidth = $(window).width();
        var f=$("."+o.f),s=f.children("#"+o.s),h=s.outerHeight(),left=f.position().left;
        f.css({position:"relative"});
        s.css({height:0,opacity:0,width:winWidth,left:-left});
        f.hover(function(){        
        s.show().stop(true,false).animate({height:h,opacity:0.8},350,function(){
                s.css({overflow:"visible"});
        });
        },function(){
                s.stop(true,false).animate({height:0,opacity:0},350,function(){
                        s.hide();
                });
        });
    }
    //网站导航下拉框
    slideMenu({
            f:"matong",
            s:"goods"
    });
});
   
  $(function(){
    var slideMenu=function(o){        
        var f=$("."+o.f),s=f.children("."+o.s),h=s.outerHeight();
        f.css({position:"relative"});
        s.css({height:0,opacity:0});
        f.hover(function(){       
        s.show().stop(true,false).animate({height:h,opacity:1},350,function(){
                s.css({overflow:"visible"});
        });
        },function(){
                s.stop(true,false).animate({height:0,opacity:0},350,function(){
                        s.hide();
                });
        });
    }
    //个人账户下拉
    slideMenu({
            f:"login_n",
            s:"mybag"
    });
    });    
   
  $(function(){
        var navbar = function(o){            
            var f = $("." + o.f), s = f.children("." + o.s), width = f.width();
            f.hover(function(){
                s.css("display", "block");
                },function(){
                s.css("display", "none");  
            });
        }
        navbar({
            f:"buy",
            s:"buy_shop"
        });
        navbar({
            f:"inactive",
            s:"inactives"
        });      
    }); 

$(document).ready(function () {    
    $(document).click(function () {
        $(".login").removeClass("login_active");
        $("#click_login").hide();
    });
    $("#click_login").click(function (event) {
        event.stopPropagation();
    });
    $(".login").click(function (event) {
        event.stopPropagation();
        $(".login").toggleClass("login_active");
        $("#click_login").toggle();
	setTimeout(function(){
            try{
                $('.text_phone').focus();
            }
            catch(e){}
        },100);
    });
    $('.text_phone').focus(function(){
        $(".notices").html("");
    });
    $('.pass').focus(function(){
        $(".notices").html("");
    });
    $(".buy").mouseover(function () {
        $("#click_login").hide();
    });    
}); 

$(".header_left_li li").click(function () {
    if ($(this).index() == 0) {
        $(".header_left_img img").attr("src", "images/images/goods_06.png");
    } else if ($(this).index() == 1) {
        $(".header_left_img img").attr("src", "images/images/goods_07.png");
    }
    else if ($(this).index() == 2) {
        $(".header_left_img img").attr("src", "images/images/goods_08.png");
    } else if ($(this).index() == 3) {
        $(".header_left_img img").attr("src", "images/images/goods_10.png");
    }
});

//ajax登录
function signIn(){
    var frm = document.forms['ECS_LOGINFORM'];    
    var username = frm.elements['username'].value;
    var password = frm.elements['password'].value;
    if (username.length == 0 || password.length == 0)
    {     
        $(".notices").html("用户名和密码不能为空");
        return;
    }

    $.ajax({
        type: 'POST',
        url: 'user.php?act=signin',
        data: {
            "username":username,
            "password":password
        },
        dataType: 'JSON',      
        success:function(result){         
           if(result.error>0){
                $(".notices").html(result.content);
            }
            else{
                window.location.reload();
            }
        }      
    });
}

//searchbar
($(document).ready(function(){
    $('.sp3').click(function(e){
        var clientH = $(document).height();         
        e.preventDefault();
        $('body').addClass('active');
        setTimeout(function(){
            try{
                $('.txt').focus();
            }
            catch(e){}
        },1000)
        $('.search-layer').css({'height':clientH});
    });
    $('.search-layer').click(function(e){
        e.preventDefault();
        $('body').removeClass('active');
     });
    $('.search-close').click(function(e){
        e.preventDefault();
        $('body').removeClass('active');
    });
}))();
 
